home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DIRS.SWG / 0004_ALLDIRS4.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  79 lines

  1. {
  2. >Is there any easy way do turn *.* wildcards into a bunch of Filenames?
  3. >This may be confusing, so here's what I want to do:
  4. >I know C, basic, pascal, and batch.  (but not too well)
  5. >I want to make a Program to read Files from c:\ece\ and, according to my
  6. >Filespecs ( *.* *.dwg plot???.plt hw1-1.c) I want the Program to take
  7. >each File individually, and Compress it and put it on b:.  I also want
  8. >the Program to work in reverse.  I.E.:  unpack Filespecs from b: and
  9. >into c:.  I want this because I take so many disks to school, and I
  10. >don't like packing and unpacking each File individually.  I also don't
  11. >want one big archive.  Any suggestions as to how to do it, or what I
  12. >could do is appreciated.
  13.  
  14. The easiest way would be to use the findfirst() and findnext()
  15. Procedures. Here's a stub Program in TP. You'll need to put code in
  16. the main routine to handle command line arguments, and call fsplit()
  17. to split up the Filenames to pass to searchDir() or searchAllDirs().
  18. then just put whatever processing you want to do With each File in
  19. the process() Procedure.
  20. }
  21.  
  22. Uses
  23.   Dos, Crt;
  24.  
  25. Var
  26.   Path      : PathStr;
  27.   Dir       : DirStr;
  28.   Name      : NameStr;
  29.   Ext       : ExtStr;
  30.   FullName  : PathStr;
  31.   F         : SearchRec;
  32.   Ch        : Char;
  33.   I         : Integer;
  34.  
  35. Procedure Process(dir : DirStr; s : SearchRec);
  36. begin
  37.   Writeln(dir, s.name);
  38. end;
  39.  
  40.  
  41. {
  42.  Both searchDir and searchAllDirs require the following parameters
  43.  path  - the path to the File, which must end With a backslash.
  44.          if there is no ending backslash these won't work.
  45.  fspec - the File specification.
  46. }
  47.  
  48. Procedure SearchDir(Path : PathStr; fspec : String);
  49. Var
  50.   f : SearchRec;
  51. begin
  52.   Findfirst(Path + fspec, AnyFile, f);
  53.   While DosError = 0 do
  54.   begin
  55.     Process(path, f);
  56.     Findnext(f);
  57.   end;
  58. end;
  59.  
  60. Procedure searchAllDirs(path : pathStr; fspec : String);
  61. Var
  62.   d : SearchRec;
  63. begin
  64.   SearchDir(Path, fspec);
  65.   FindFirst(Path + '*.*', Directory, d);
  66.   While DosError = 0 do
  67.   begin
  68.     if (d.Attr and Directory = Directory) and (d.name[1] <> '.') then
  69.     begin
  70.       SearchAllDirs(Path + d.name + '\', fspec);
  71.     end;
  72.     Findnext(d);
  73.   end;
  74. end;
  75.  
  76. begin
  77.   SearchAllDirs( '\', '*.*' );
  78. end.
  79.